package com.czn.datasourcesync.controller;

import com.czn.datasourcesync.service.SyncDataSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zenan Chen
 * @date 2023/9/14 16:08
 */
@Api(tags = "整库同步控制器")
@RestController
@RequestMapping("/syncDS")
public class SyncDataSourceController {

    private static final Logger log = LoggerFactory.getLogger(SyncDataSourceController.class);
    @Autowired
    private SyncDataSourceService syncDataSourceService;

    @ApiOperation(value = "手动进行整库同步")
    @PostMapping("/sync")
    public Object sync() {
        try {
            syncDataSourceService.sync();
            return "手动进行整库同步成功！";
        } catch (Exception e) {
            log.error("------------->/syncDS/sync 接口异常: ", e);
            return "手动进行整库同步失败：" + e.getMessage();
        }
    }
}
